Skip to content

fix(fb_custom_audience): one invalid event causes entire batch to fail#5036

Merged
shekhar-rudder merged 2 commits intodevelopfrom
int-5922-fb-audience-partial-error
Mar 11, 2026
Merged

fix(fb_custom_audience): one invalid event causes entire batch to fail#5036
shekhar-rudder merged 2 commits intodevelopfrom
int-5922-fb-audience-partial-error

Conversation

@shekhar-rudder
Copy link
Member

Summary

  • When a record with all-null user properties was in a batch, the thrown error caused the entire batch (including valid records) to fail
  • processRecord now returns an error field instead of throwing, and processRecordEventArray separates valid/invalid records into success and error responses
  • Added test case for all-events-failure scenario; updated existing test to expect partial success

Test plan

  • All 48 component tests pass (npm run test:ts -- component --destination=fb_custom_audience)
  • All 24 unit tests pass (npx jest --testPathPattern="fb_custom_audience")
  • Covers: all success, all failure, partial success scenarios

🤖 Generated with Claude Code

@shekhar-rudder shekhar-rudder requested a review from a team as a code owner March 11, 2026 09:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'auto_resolve_threads'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Summary by CodeRabbit

  • Refactor

    • Facebook Custom Audience processing now returns structured results that include both successful items and reported validation errors, enabling partial-success payloads instead of hard failures.
  • Bug Fixes

    • Batches with no valid records are safely short-circuited and error details are aggregated so invalid events are reported alongside any successful data.

Walkthrough

Error handling in the Facebook Custom Audience record transformation was changed from throwing exceptions to returning error objects alongside metadata. Batch-processing functions now return both successful payloads and accumulated invalid events; imports and public method signatures were updated to reflect the new return shapes.

Changes

Cohort / File(s) Summary
Record transform (FB Custom Audience)
src/v0/destinations/fb_custom_audience/recordTransform.ts
Reworked error handling: processRecord now returns `{ metadata } & ({ dataElement[] }

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing an issue where invalid events in a batch caused the entire batch to fail, which is the primary objective of this PR.
Description check ✅ Passed The PR description provides a clear summary of changes, test coverage details, and confirms all tests pass. However, it lacks several template sections including Linear task reference, technical considerations, and developer checklist completion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch int-5922-fb-audience-partial-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/v0/destinations/fb_custom_audience/recordTransform.ts (1)

119-145: Consider whether async iteration is necessary for synchronous processing.

The inner forEachInBatches at line 121 wraps a synchronous processRecord call. This introduces unnecessary async overhead. A regular forEach or for...of loop would be more efficient here.

♻️ Suggested refactor
   await forEachInBatches(recordChunksArray, async (recordArray) => {
     const data: unknown[][] = [];
-    await forEachInBatches(recordArray, async (input) => {
-      const result = processRecord(
+    for (const input of recordArray) {
+      const result = processRecord(
         input,
         userSchema,
         isHashRequired,
         disableFormat,
         input.metadata.workspaceId,
         destination.ID,
       );
       if (result.error) {
         const error = new InstrumentationError(result.error);
         const errorObj = generateErrorObject(error);
         invalidEvents.push(
           getErrorRespEvents(
             [result.metadata],
             errorObj.status,
             errorObj.message,
             errorObj.statTags,
           ),
         );
       } else {
         data.push(result.dataElement!);
         metadata.push(result.metadata);
       }
-    });
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/v0/destinations/fb_custom_audience/recordTransform.ts` around lines 119 -
145, The inner async batch iterator is unnecessary because processRecord is
synchronous; replace the inner await forEachInBatches(recordArray, async (input)
=> { ... }) with a synchronous loop (e.g., for...of or Array.prototype.forEach)
over recordArray, call processRecord directly, and push to data/metadata or
invalidEvents as before, removing the async callback and the extra await to
avoid unnecessary async overhead; keep outer forEachInBatches over
recordChunksArray intact and preserve usage of variables recordArray,
processRecord, invalidEvents, data, and metadata.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/v0/destinations/fb_custom_audience/recordTransform.ts`:
- Around line 119-145: The inner async batch iterator is unnecessary because
processRecord is synchronous; replace the inner await
forEachInBatches(recordArray, async (input) => { ... }) with a synchronous loop
(e.g., for...of or Array.prototype.forEach) over recordArray, call processRecord
directly, and push to data/metadata or invalidEvents as before, removing the
async callback and the extra await to avoid unnecessary async overhead; keep
outer forEachInBatches over recordChunksArray intact and preserve usage of
variables recordArray, processRecord, invalidEvents, data, and metadata.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b043191-611c-40f8-a568-ae4975261ee2

📥 Commits

Reviewing files that changed from the base of the PR and between d4d9801 and 5183b9e.

⛔ Files ignored due to path filters (2)
  • test/integrations/destinations/fb_custom_audience/router/data.ts is excluded by !**/test/**
  • test/integrations/destinations/fb_custom_audience/router/rETL.ts is excluded by !**/test/**
📒 Files selected for processing (1)
  • src/v0/destinations/fb_custom_audience/recordTransform.ts

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.27%. Comparing base (d4d9801) to head (ab225f2).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5036   +/-   ##
========================================
  Coverage    92.27%   92.27%           
========================================
  Files          657      657           
  Lines        35941    35956   +15     
  Branches      8480     8485    +5     
========================================
+ Hits         33163    33178   +15     
  Misses        2540     2540           
  Partials       238      238           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/v0/destinations/fb_custom_audience/recordTransform.ts`:
- Around line 121-144: Wrap the call to processRecord inside a try/catch so
thrown exceptions per record are caught and converted to invalidEvents instead
of rejecting the whole batch: call processRecord(...) inside try, handle the
existing 'error'-in-result branch as-is, and in catch create an
InstrumentationError from the thrown error, call generateErrorObject on it, then
push getErrorRespEvents using input.metadata (since result may not exist) into
invalidEvents; ensure on catch you continue the loop (do not rethrow) so other
records in the batch are processed. Use the existing symbols: forEachInBatches,
processRecord, InstrumentationError, generateErrorObject, getErrorRespEvents,
invalidEvents, data, and metadata.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 741fc232-1c49-4a44-82a7-54b69e6c0956

📥 Commits

Reviewing files that changed from the base of the PR and between 5183b9e and ab225f2.

📒 Files selected for processing (1)
  • src/v0/destinations/fb_custom_audience/recordTransform.ts

@shekhar-rudder shekhar-rudder merged commit 8dca5a2 into develop Mar 11, 2026
33 of 34 checks passed
@shekhar-rudder shekhar-rudder deleted the int-5922-fb-audience-partial-error branch March 11, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants